package com.bjsxt;

import java.awt.*;

/**
 * @Project: PlaneFight
 * @Author: 陈祖生
 * @Version: 1.0
 * @CreateTime: 2022/7/1 16:30
 * @Description: 炮弹
 */
public class Shell extends GameObject{
    double degree;

    @Override
    public void drawMyself(Graphics g) {
        Color c = g.getColor();
        g.setColor(Color.yellow);
        g.fillOval(x,y,width,height);
        //炮弹沿着任意角度飞行
        x += speed * Math.cos(degree);
        y += speed * Math.sin(degree);

        //实现边界碰撞回弹
        if (y > GameUtil.FRAME_HIGTH-10){
            degree = -degree;
        }
        if (y < 30){
            degree = -degree;
            y = y + 5;
        }

        if (x > GameUtil.FRAME_WIDTH-10){
            degree = Math.PI-degree;

        }
        if (x < 10){
            degree = Math.PI-degree;
            x = x + 5;
        }



        g.setColor(c);
    }

    public Shell() {
        degree = Math.random()*Math.PI*2;
        x = 20;
        y = 20;
        width = 10;
        height = 10;
        speed = 30;
    }
}
